﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{   
    public class ReportType_Proprietary : ReportType_Base
    {
        #region private member variables

        private byte _proprietaryNibble;

        #endregion private member variables

        #region constructor

        /// <summary>
        /// Constructor, proprietaryNibble only allows values 0 .. 15
        /// </summary>
        /// <param name="onOffFlag"></param>
        /// <param name="proprietaryNibble">only values 0 .. 15 allowed, greater values will be reduced automatically to 15</param>
        public ReportType_Proprietary(bool onOffFlag, byte proprietaryNibble)
            : base(onOffFlag)
        {
            // only take the lower nibble
            _proprietaryNibble = (byte) (proprietaryNibble & 0x0f);
        }

        #endregion constructor

        #region getters

        /// <summary>
        /// The proprietary nibble (0 .. 15, 0x00 .. 0x0F)
        /// </summary>
        public byte ProprietaryNibble { get { return _proprietaryNibble; } }

        #endregion getters

        #region ToString, Equals, GetHashCode

        public override int GetHashCode()
        {
            int hashCode = base.GetHashCode();
            hashCode ^= _proprietaryNibble;

            return hashCode;
        }

        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("(");
            stringBuilder.Append(ToStringProperties());
            stringBuilder.Append(")");

            return stringBuilder.ToString();
        }

        internal override string ToStringProperties()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.ToStringProperties());

            stringBuilder.Append(", ");

            stringBuilder.Append("ProprietaryNibble='");
            stringBuilder.Append(_proprietaryNibble);
            stringBuilder.Append("'");

            return stringBuilder.ToString();
        }

        public override bool Equals(object obj)
        {
            Type objType = obj.GetType();
            if (this.GetType() == objType)
            {
                ReportType_Proprietary reportTypeProprietary2Compare = obj as ReportType_Proprietary;
                return EqualsProperties(reportTypeProprietary2Compare);
            }

            return false;
        }

        internal bool EqualsProperties(ReportType_Proprietary reportTypeProprietary2Compare)
        {
            if (base.EqualsProperties(reportTypeProprietary2Compare))
            {
                return (ProprietaryNibble == reportTypeProprietary2Compare.ProprietaryNibble);
            }

            return false;
        }

        #endregion ToString, Equals, GetHashCode
    }    
}
